<?php
/**
 * $Id: live_events_controller.php 126 2009-02-23 10:18:42Z gpo_shrey $
 * 
 * This file can not be redistributed to anyone without the permission of Giga Promoters
 * Copyright 2005 - 2008, Giga Promoters
 * 						  608 Aggarwal Cyber Plaza
 *						  Netaji Subhash Place, Delhi - 110034
 *						  www.gigapromoters.com
 * 
 *
 * This is parent of parent class of a controller and should not be edited ever without permission.
 * @version 			$Rev: 126 $
 * @lastModifiedBy		$LastChangedBy: gpo_shrey $
 * @lastChanged			$Date: 2009-02-23 15:48:42 +0530 (Mon, 23 Feb 2009) $
 * @copyright 			Giga Promoters (www.gigapromoters.com)
 * 
 */

/**
 * Handles AJAX live events page
 *
 */
class LiveEventsController extends CmsAppController
{
	var $name = 'LiveEvents';

	var $components = array('RequestHandler');

	/**
	 * Shows some last 'n' events happening around.
	 * This function also requires some serious refactoring.
	 *
	 */
	function getLastEvents()
	{
		if(isset($_POST['timestamp']))
		{
			$timestamp = $_POST['timestamp'];
		}
		else
		{
			// set sample timestamp for demo
			$timestamp = '2008-09-16 13:50:44';
		}
		Configure::write('debug', 0);
		$this->layout = 'ajax';


		// get all events after $id
		//echo "fetching all events after ".$id;
		
		// reset old timestamp
		$timestampOld = $_SESSION['timestampLast'];

		// get latest timestamp and set in session
		$timestampLatest = $timestamp;
		$_SESSION['timestampLast'] = $timestampLatest;

		//echo "<div>".$timestamp."</div>";
		//exit;

		$events = $this->LiveEvent->findAll(array('LiveEvent.time >='=>$timestampOld, 'LiveEvent.time <='=>$timestamp), null, null, 5);
		$this->set('events', $events);

		$this->set('timestampOld', $timestampOld);
		$this->set('timestamp', $timestamp);
	}
	
	function eventFeed()
	{
		Configure::write('debug',0);
		$liveEvents = $this->LiveEvent->find('all',array('limit'=>20,'order'=>'time desc'));
		$this->set('liveEvents',$liveEvents);

		$channel = array ('title' => 'Beanhunter Event Feed', 'link' => Configure::read('cmsConfig.Backend.siteUrl').'/eventFeed', 'description' => ' Channel-Event Feed');
		$this->RequestHandler->renderAs($this,'rss');
		$this->set('channelData',$channel);
	}
}

?>